<extend name="Public:Base" />
<block name="title">
    <title>美住 - 默认分销渠道</title>
</block>
<block name="extendHead">
    <link rel="stylesheet" href="__PUBLIC__/src/meizhu/HotelChannel/index.css"/>
</block>
<block name="document">
    <div id="doc" data-side-menu-id="sideMenuHotelChannel" data-side-menu-toggle-id="collapseHotelSetting">
        <div id="doc-header">
            <include file="Public:Include_navbar" />
        </div>
        <div id="doc-center">
            <div class="container">
                <div class="col-xs-3-15">
                    <include file="Public:Include_sideMenu" />
                </div>
                <div class="col-xs-12-15">
                    <nav class="navbar navbar-default navbar-custom-fitin">
                        <div class="container-fluid">
                            <p class="navbar-text custom-navber-text">客栈默认分销渠道列表</p>
                        </div>
                    </nav>
                    <nav class="navbar navbar-default navbar-custom-fitin nav-padding">
                        <div class="container-fluid">
                            <div class="collapse navbar-collapse">
                                <input type='text' id='hotelChannelAddName' />
                                <button id='submitAdd'>添加</button>
                            </div>
                        </div>
                    </nav> 
                    <div class="well well-custom-has-navbar">
                        <div class="well-custom-body">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover" id="questionTalbe">
                                    <thead>
                                        <tr>
                                            <th>名字</th>
                                            <th>创建时间</th>
                                            <th>创建人</th>
                                            <th class="col-xs-1-15">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="channel" item="vo">
                                        <tr>
                                            <td><span class='channelName'>{$vo.name}</span></td>
                                            <td>{$vo.createtime|substr=0,10}</td>
                                            <td>{$vo.creator}</td>
                                            <td>
                                                <button class="btn btn-default btn-sm view submitDelete">删除</button>
                                            </td>
                                        </tr>
                                    </foreach>
                                    <tr class="padtopx"><td colspan="5">{$page}</td></tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div id="doc-footer">
            <include file="Public:Include_footer" />
        </div>
    </div>
    <!--end of doc-->
</block>

<block name="extendFootJs">
    <script type="text/javascript" src="__PUBLIC__/src/meizhu/common.js"></script>    
    <script type="text/javascript" src="__PUBLIC__/uclbrt/js/jquery-plugin/tooltip.js"></script>
    <script type="text/javascript">
    $(function() {
        $('#submitAdd').on('click', function() {
            var newChannel = $('#hotelChannelAddName').val().trim(),
                me = $(this);
            if (newChannel.length <= 0 || newChannel.length > 50) {
                tooltipWrong(me, '长度为1-50字', 3);
                return false;
            }

            var params = {
                name: newChannel
            };

            ajaxRequest('/Home/Setting/addChannel', params, 'post', function(data) {
                window.location.reload();
            }, function(error) {
                if (error.responseJSON === undefined) {
                    tooltipWrong(me, '系统繁忙', 3);
                    return false;
                }
                tooltipWrong(me, error.responseJSON.info, 3);
            });
        });

        $('.submitDelete').on('click', function() {
            var me = $(this),
                name = me.parents('tr').find('.channelName').text().trim();

            if (name.length <= 0 || name.length > 50) {
                return false;
            }

            var params = {
                name: name
            };

            ajaxRequest('/Home/Setting/deleteChannel', params, 'post', function(data) {
                window.location.reload();
            }, function(error) {
                if (error.responseJSON === undefined) {
                    tooltipWrong(me, '系统繁忙', 3);
                    return false;
                }
                tooltipWrong(me, error.responseJSON.info, 3);
            });
        });
    });
    </script>
</block>

